p_bar <- gapminder %>%filter(year >=1990) %>%# Keep only years from 1990 onwardgroup_by(year, continent) %>%summarize(lifeExp =mean(lifeExp), .groups ="drop") %>%ggplot(aes(x =factor(year), y = lifeExp, fill = continent)) +geom_col(position ="dodge") +labs(title ="Average Life Expectancy by Continent (1990+)",x ="Year",y ="Life Expectancy",fill ="Continent") +theme_bw()plotly::ggplotly(p_bar)
Code
data <- gapminder g <-ggplot(data, aes(x = lifeExp, fill =factor(year))) +geom_histogram(binwidth =2, alpha =0.6, position ="identity") +labs(title ="Histogram of Life Expectancy by Year",x ="Life Expectancy",y ="Count",fill ="Year") +theme_minimal()plotly::ggplotly(g)
Code
g <-ggplot(data, aes(x = gdpPercap, y = lifeExp, color = continent)) +geom_point(alpha =0.6) +scale_x_log10() +labs(title ="Life Expectancy vs GDP per Capita",x ="GDP per Capita (log scale)",y ="Life Expectancy",color ="Continent") +theme_minimal()plotly::ggplotly(g)